from paddleocr import PaddleOCR
import uuid
import os
import yaml
from PIL import ImageGrab
from PIL import Image
import imgCompare

import cv2


def compare2pics(img1, img2):
    img1 = cv2.imread(img1)
    img2 = cv2.imread(img2)
    hash1 = imgCompare.aHash(img1)
    hash2 = imgCompare.aHash(img2)
    n = imgCompare.cmpHash(hash1, hash2)
    print(n)
    return n > 0.9


# 读取配置文件
def dict2namespace():
    with open('config.yml', 'r', encoding='utf-8') as f:
        data = yaml.load(f, Loader=yaml.FullLoader)
        return data


# Paddleocr目前支持中英文、英文、法语、德语、韩语、日语，可以通过修改lang参数进行切换
# 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。


configs = dict2namespace()
path = os.getcwd()
x, y, x2, y2 = configs['location']['jietu']['tuporesult']['x'], configs['location']['jietu']['tuporesult'][
    'y'], configs['location']['jietu']['tuporesult']['x2'], configs['location']['jietu']['tuporesult']['y2']
area = (x, y, x2, y2)   # 这里是设置截图范围的区域
shot = ImageGrab.grab(area)
filename = path+'\\pics\\'+str(uuid.uuid1())+'.png'
shot.save(filename)
 
# ocr = PaddleOCR(use_angle_cls=True, lang="ch") 
# result = ocr.ocr(filename, cls=True)
# val = ''
# for line in result:
#     for item in line:
#         val += (item[1][0]) 
print(compare2pics('target\\empty.png',filename))   


# if __name__ == "__main__":
    
#     blackList=['馨乐菲','黑名单']
#     isBlick=False
#     isBlack = False
#     if '馨乐菲' not in blackList:
#         isBlack = True
#     print(blackList.count('馨乐菲1')>0)